package main

import (
	"fmt"
	"time"
)

// 利用 select 实现延迟
func main() {
	quit := make(chan bool)
	ch := make(chan int)

	go func() {
		for {
			select {
			case <-time.After(time.Second * 3): // ? 为什么最后才运行？
				fmt.Println("Over")
				quit <- true

			case num := <-ch:
				fmt.Println(num)
			}
		}
	}()

	for i := 1; i <= 10; i++ {
		ch <- i
		time.Sleep(time.Second)
	}
	<-quit
}
